﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Taxonomy;
using MS.InformationManagement.Support;
using MS.InformationManagement.Support.Constants;

namespace MS.InformationManagement.BLL.TaxonomyTerms
{
    public class TaxonomyTerms
    {

        public TermCollection GetCountries()
        {
            return TermStoreHelper.GetTermSetByName(GlobalConstants.METADATA_GROUP_NAME, GlobalConstants.METADATA_TERM_COUNTRY).Terms;
        }

        public TermCollection GetStates(string country)
        { 
            Term selectedCountry =(from term in TermStoreHelper.GetTermSetByName(GlobalConstants.METADATA_GROUP_NAME, GlobalConstants.METADATA_TERM_COUNTRY).Terms.OfType<Term>()
                                   where term.Name == country
                                   select term).FirstOrDefault();
            return selectedCountry == null ? null : selectedCountry.Terms;
        }

        public TermCollection GetCities(string country, string state)
        {
            TermCollection selectedStates = GetStates(country);
            Term selectedState = (from currentState in selectedStates.OfType<Term>()
                                  where currentState.Name == state
                                  select currentState).FirstOrDefault();
            return selectedState == null ? null : selectedState.Terms;
        }

        public TermCollection GetCategory()
        {
            return TermStoreHelper.GetTermSetByName(GlobalConstants.METADATA_GROUP_NAME, GlobalConstants.METADATA_TERM_CATEGORY).Terms;
        }



    }
}
